//
// Created by francklinson on 2021/11/27 AT 18:06.
// May Saint Diana bless you!
//

#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>

using namespace std;

class Solution {
public:
    vector<string> uncommonFromSentences(string s1, string s2) {
        // 统计单词出现的次数
        unordered_map<string, int> counter;
        int start = 0;
        for (int i = 0; i < s1.size(); ++i) {
            if (i == s1.size() - 1 || s1[i + 1] == ' ') {
                ++counter[s1.substr(start, i - start + 1)];
                start = i + 2;
            }
        }
        start = 0;
        for (int i = 0; i < s2.size(); ++i) {
            if (i == s2.size() - 1 || s2[i + 1] == ' ') {
                ++counter[s2.substr(start, i - start + 1)];
                start = i + 2;
            }
        }
        vector<string> ans;
        for (const auto &p: counter) {
            if (p.second == 1)
                ans.push_back(p.first);
        }
        return ans;
    }
};

int main() {
    Solution solution;
    vector<string> ans = solution.uncommonFromSentences("this apple is sweet", "this apple is sour");
    for (const string &x: ans)
        cout << x << endl;
    return 0;
}

